﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace pigs
{
    public class Man
    {

        // Sprite representing the man
        public Texture2D Texture;

        // Position of the man
        public Vector2 Position;

        // Speed of rotation
        float rotation;

        public SpriteEffects spriteeffect;

        //initialize the man
        public void Initialize(Texture2D texture, Vector2 position, float rotation)
        {
            this.rotation = rotation;
            Texture = texture;
            Position = position;
            spriteeffect = SpriteEffects.None;
        }

        // Make the man point his gun at the aimer
        public void Update(Vector2 aim)
        {
                rotation = (float)(Math.Atan2(aim.Y, aim.X));
        }


        //draw the man
        public void Draw(SpriteBatch spriteBatch)
        {
            // The point to pivot around (center of image)
            Vector2 origin = new Vector2( Texture.Width / 2, Texture.Height / 2);

            spriteBatch.Draw(Texture, Position, null, Color.White, this.rotation, origin, 1f, spriteeffect, 0f);
        }
    }
}